//
//  TransitionAnimationVC.m
//  Home
//
//  Created by 曹连华 on 2019/7/2.
//  Copyright © 2019 曹连华. All rights reserved.
//

#import "TransitionAnimationVC.h"
#import "TransitionAnimationViewModel.h"
#import "NavigationTransiitionVC.h"
#import <ServiceCode/ServiceCode.h>
#import <Masonry/Masonry.h>
@interface TransitionAnimationVC ()<UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) TransitionAnimationDelegate *transitionDelegate;
@property (nonatomic, strong) TransitionAnimationViewModel *viewModel;

@end

@implementation TransitionAnimationVC

+ (void)load {
    RouterVO *vo = [RouterVO new];
    vo.tab = NO;
    vo.createdType = PBRouteObjectCreateByCode;
    vo.className = NSStringFromClass(self);
    vo.keyInfo = @"转场动画示例页面";
    [[Router sharedInstance]registerRouterVO:vo withKey:@"transitionanimation"];
}
- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero];
        _tableView.delegate = self;
        _tableView.dataSource = self.viewModel.dataSource;
        _tableView.estimatedRowHeight = 120;
        _tableView.separatorStyle = UITableViewCellSelectionStyleNone;
        _tableView.rowHeight = UITableViewAutomaticDimension;
        _tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    }
    return _tableView;
}
- (TransitionAnimationDelegate *)transitionDelegate {
    if (!_transitionDelegate) {
        _transitionDelegate = [[TransitionAnimationDelegate alloc]init];
    }
    return _transitionDelegate;
}
- (TransitionAnimationViewModel *)viewModel {
    if(!_viewModel) {
        _viewModel = [[TransitionAnimationViewModel alloc]init];
    }
    return _viewModel;
}
-(void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
}

- (void)initUI {
    self.navigationItem.title = @"转场动画";
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.bottom.top.leading.mas_equalTo(0);
    }];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    TransitionAnimationTVCellModel *rowModel = (TransitionAnimationTVCellModel *)[self.viewModel.dataSource rowModelAtIndex:indexPath];
    if ([rowModel.subTitle isEqualToString:@"Push/Pop-smallInBigOut"]) {
        
        [self.transitionDelegate updateTransitionAnimation:[TransitionAnimationCustom animationType:AnimationTypeSmallInBigOut]];
        
    } else if ([rowModel.subTitle isEqualToString:@"Push/Pop-smallRoundInBigOutRound"]) {
        
        [self.transitionDelegate updateTransitionAnimation:[TransitionAnimationCustom animationType:AnimationTypeSmallRoundInBigRoundOut]];
        
    }
    [Router sharedInstance].currentNC.delegate = self.transitionDelegate;
    [[Router sharedInstance]routeWithKey:@"navigationtransiition"];
}

- (void)leftBtnClicked:(id)sender {
    [Router sharedInstance].currentNC.delegate = nil;
    [super leftBtnClicked:sender];
}
@end
